from tkinter import Tk
from tkinter import Menu
from tkinter import ttk

from database.table import tablee
from database.table.tablee import Employ
from database.employ.employ_buy import BuyPage
from database.employ.employ_commodity import CommodityPage

def EmployPage(id):
    employ_screen = Tk()
    employ_screen.title('超市进销存管理系统')
    # 屏幕的宽度和高度
    screen_width, screen_height = employ_screen.maxsize()
    # 窗口的宽和高
    width = 610
    height = 100
    centre = '%dx%d+%d+%d' % (width, height, (screen_width - width) / 2,
                              (screen_height - height) / 2)
    employ_screen.geometry(centre)

    tree = ttk.Treeview(employ_screen)  # 创建表格对象
    tree["columns"] = ("编号", "姓名", "密码", "级别", "电话", "工资", "备注")
    tree.column("编号", width=50)  # 设置列
    tree.column("姓名", width=50)
    tree.column("密码", width=50)
    tree.column("级别", width=50)
    tree.column("电话", width=100)
    tree.column("工资", width=50)
    tree.column("备注", width=50)
    tree.heading("编号", text="编号")  # 显示表头名
    tree.heading("姓名", text="姓名")
    tree.heading("密码", text="密码")
    tree.heading("级别", text="级别")
    tree.heading("电话", text="电话")
    tree.heading("工资", text="工资")
    tree.heading("备注", text="备注")

    employee = tablee.session.query(Employ).filter(Employ.Eno == id).all()
    data = Employ.to_json(employee)
    length = len(data)

    for i in range(0, length):
        num = data[i]['Eno']
        name = data[i]['Ename']
        password = data[i]['Epassword']
        level = data[i]['Elevel']
        phone = data[i]['Ephone']
        pay = data[i]['Epay']
        remarks = data[i]['Eremarks']
        tree.insert("", 0, text='', value=(num, name, password, level, phone, pay, remarks))
    tree.pack()

    tablee.session.close()

    def buy(): #采购信息
        BuyPage()

    def commodity():#供应商信息
        CommodityPage()

    def employ_screen_quit():
       employ_screen.destroy()

    menu_employ = Menu(employ_screen) #顶级菜单
    menu_employ_child = Menu(menu_employ)  # 顶级菜单下的子菜单
    # 子菜单绑定到顶级菜单
    menu_employ.add_cascade(label='查看', menu=menu_employ_child)
    menu_employ.add_command(label='退出',command=employ_screen_quit)
    #子菜单
    menu_employ_child.add_command(label='商品信息',command=commodity)
    menu_employ_child.add_command(label='采购信息', command=buy)

    employ_screen.config(menu=menu_employ)

    employ_screen.mainloop()

if __name__=='__main__':
    EmployPage()